package com.isunland.managesystem.adapter;

import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import com.amulyakhare.textdrawable.TextDrawable;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseButterKnifeAdapter;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.entity.WorkprocessFinish.FinishDtail;
import com.isunland.managesystem.utils.MyStringUtil;
import java.util.ArrayList;

/**
 * 已完成工作列表适配器
 *
 * @author wu
 */
public class WrokProcessFinishAdapter extends BaseButterKnifeAdapter<FinishDtail> {
  // Constructors
  public WrokProcessFinishAdapter(BaseVolleyActivity context, ArrayList<FinishDtail> objects) {
    super(context, objects);
  }

  @Override protected int setLayoutId() {
    return R.layout.adapter_file;
  }

  @NonNull @Override protected BaseViewHolder initHolder(View convertView) {
    return new ViewHolder(convertView);
  }

  @Override protected void initView(FinishDtail item, BaseViewHolder baseHolder, int position) {
    ViewHolder holder = (ViewHolder) baseHolder;
    holder.tvFileName.setText(item.getPlanContentDesc());
    holder.tvDate.setText(
        context.getString(R.string.lattestFinishTimeWithHolder, item.getPlanStagecompleteTime()));
    holder.ivMore.setTag(item);
    @SuppressWarnings("deprecation") TextDrawable drawable = TextDrawable.builder()
        .beginConfig()
        .fontSize(50)
        .endConfig()
        .buildRound(MyStringUtil.substring(item.getWorkTime(), 0, 1),
            context.getResources().getColor(R.color.primary));
    holder.ivFile.setImageDrawable(drawable);
  }

  protected class ViewHolder extends BaseViewHolder {
    @SuppressWarnings("unused") @BindView(R.id.iv_file) ImageView ivFile;
    @BindView(R.id.tv_fileName) TextView tvFileName;
    @BindView(R.id.tv_date) TextView tvDate;
    @BindView(R.id.iv_more) ImageView ivMore;

    ViewHolder(View view) {
      super(view);
      ivMore.setVisibility(View.INVISIBLE);
    }
  }
}

